package com.mjh.controller;

import com.github.pagehelper.PageInfo;
import com.mjh.model.R;
import com.mjh.service.CustomerService;
import com.mjh.vo.CustomerVo;
import com.mjh.vo.CustomerVoo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 分页查询客户信息列表
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/page")
    public R<PageInfo<CustomerVo>> loadCustomerPage(@RequestParam Integer current,
                                                    @RequestParam(required = false, defaultValue = "10") Integer size) {

        PageInfo<CustomerVo> pageInfo = customerService.queryCustomerListByPage(current, size);
        return R.OK(pageInfo);
    }
    /**
     * 删除客户信息
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public R<String> removeCustomerById(@PathVariable Integer id) {
        Boolean result = customerService.removeCustomerById(id);
       return R.HANDLER(result);
    }
    @GetMapping("/list")
    public R<List<CustomerVoo>> loadCustomerList() {
        List<CustomerVoo> customerList = customerService.queryAllCustomerList();
        return R.OK(customerList);
    }

}
